Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolved border collapse issue #1626 when border variants are mixed in button group #1637

Merged
merged 20 commits into from
Oct 4, 2023

Conversation

chongruei
Copy link
Contributor

Closes #1626

📝 Description

The radius property does not work on the 'buttonGroup' component. The variant="bordered" option does not display the correct borders.

⛳️ Current behavior (updates)

The radius is always the same as md.
The border-left is covered by margin-left ml-[calc(theme(borderWidth.medium)*-1)].

  <ButtonGroup color="success" radius="lg" variant="flat">
    <Button>One</Button>
    <Button>Two</Button>
    <Button variant="bordered">Three</Button>
    <Button>Four</Button>
    <Button>Five</Button>
    <Button>Six</Button>
  </ButtonGroup>

🚀 New behavior

The radius now works, and the border is displayed correctly in the buttonGroup.

💣 Is this a breaking change (Yes/No):

No

📝 Additional Information

Please kindly let me know if any suggestions.

@changeset-bot
Copy link

changeset-bot bot commented Sep 16, 2023

🦋 Changeset detected

Latest commit: f89b7c9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 36 packages
Name Type
@nextui-org/button Patch
@nextui-org/theme Patch
@nextui-org/card Patch
@nextui-org/dropdown Patch
@nextui-org/modal Patch
@nextui-org/navbar Patch
@nextui-org/popover Patch
@nextui-org/radio Patch
@nextui-org/snippet Patch
@nextui-org/table Patch
@nextui-org/tabs Patch
@nextui-org/tooltip Patch
@nextui-org/react Patch
@nextui-org/accordion Patch
@nextui-org/avatar Patch
@nextui-org/badge Patch
@nextui-org/checkbox Patch
@nextui-org/chip Patch
@nextui-org/code Patch
@nextui-org/divider Patch
@nextui-org/image Patch
@nextui-org/input Patch
@nextui-org/kbd Patch
@nextui-org/link Patch
@nextui-org/listbox Patch
@nextui-org/menu Patch
@nextui-org/pagination Patch
@nextui-org/progress Patch
@nextui-org/ripple Patch
@nextui-org/scroll-shadow Patch
@nextui-org/select Patch
@nextui-org/skeleton Patch
@nextui-org/spacer Patch
@nextui-org/spinner Patch
@nextui-org/switch Patch
@nextui-org/user Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Sep 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 1, 2023 3:29pm

@vercel
Copy link

vercel bot commented Sep 16, 2023

@chongruei is attempting to deploy a commit to the NextUI Team on Vercel.

A member of the Team first needs to authorize it.

@jguddas
Copy link
Contributor

jguddas commented Sep 16, 2023

@chongruei chongruei closed this Sep 16, 2023
@Digoler
Copy link

Digoler commented Sep 16, 2023

I am a new frontend developer who wants to improve programming skills through open source. I would like to know how you solved this problem. Could you please tell me the reasons and solutions for this problem?

@jguddas
Copy link
Contributor

jguddas commented Sep 16, 2023

I am a new frontend developer who wants to improve programming skills through open source. I would like to know how you solved this problem. Could you please tell me the reasons and solutions for this problem?

It wasn't solved.

@chongruei
Copy link
Contributor Author

chongruei commented Sep 16, 2023

Hi @jguddas

Sorry, I've missed radius as the default prop from theme.ts. Could you check this again?

@jguddas
Copy link
Contributor

jguddas commented Sep 16, 2023

Can you add something like this as a story?

  <ButtonGroup color="success" radius="lg" variant="flat">
    <Button>One</Button>
    <Button>Two</Button>
    <Button variant="bordered">Three</Button>
    <Button>Four</Button>
    <Button>Five</Button>
    <Button>Six</Button>
  </ButtonGroup>

@Digoler
Copy link

Digoler commented Sep 16, 2023

Hi @jguddas

Sorry, I've missed radius as the default prop from theme.ts. Could you check this again?

Can you tell me why you added an isIsolate attribute instead of directly taking the following approach?

image

@Digoler
Copy link

Digoler commented Sep 16, 2023

Hi @jguddas
Sorry, I've missed radius as the default prop from theme.ts. Could you check this again?

Can you tell me why you added an isIsolate attribute instead of directly taking the following approach?

image

This can also solve this problem.

@chongruei
Copy link
Contributor Author

Hi @jguddas
Sorry, I've missed radius as the default prop from theme.ts. Could you check this again?

Can you tell me why you added an isIsolate attribute instead of directly taking the following approach?
image

This can also solve this problem.

Hi, @Digoler, it would be like without isIsolate

Screenshot 2023-09-17 at 1 26 04 AM

After defining the isIsolate

Screenshot 2023-09-17 at 1 29 51 AM

@chongruei
Copy link
Contributor Author

Hi! @jguddas

I finally removed the negative value for the margin because it always covered the neighbor.

Like this
Screenshot 2023-09-18 at 1 12 34 AM

It appears that removing the negative value for the margin has led to a situation where the border size doubles when the colors are the same. What are your thoughts on this issue?
Screenshot 2023-09-18 at 1 20 43 AM

@jguddas
Copy link
Contributor

jguddas commented Sep 17, 2023

It appears that removing the negative value for the margin has led to a situation where the border size doubles when the colors are the same. What are your thoughts on this issue? Screenshot 2023-09-18 at 1 20 43 AM

Yeah, not a great look.

My proposal: keep the isIsolated but only have it be true when groupContext.variant !== props.variant.

The edge cases have to be handled by the user, I don't see another way.

@jguddas
Copy link
Contributor

jguddas commented Sep 17, 2023

Another idea:

We could use peer and a data-variant attribute.

https://play.tailwindcss.com/Dl8H3CEOfv

Edit: peer uses ~, we would need something like peer that uses + instead.

We would have to copy this into the next plugin:

https://github.com/tailwindlabs/tailwindcss/blob/42e75ba4b860ef75656cff3119aa56e70714d34c/src/corePlugins.js#L151-L202

Than something like this would work:
https://play.tailwindcss.com/mtNmipDgp4

@chongruei
Copy link
Contributor Author

Hi @jguddas

Thank you for your suggestion, which has provided me with a lot of inspiration. I have finally used an adjacent selector to check if the color and variant are the same. If they are the same, I will add a margin-left effect.

This approach will cover all edge cases.

variant: ["ghost", "bordered"],
color: "default",
className:
"nextui-adjacent-default [&+.nextui-adjacent-default]:ml-[calc(theme(borderWidth.medium)*-1)]",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer using data-color and data-variant over .nextui-adjacent-…

Suggested change
"nextui-adjacent-default [&+.nextui-adjacent-default]:ml-[calc(theme(borderWidth.medium)*-1)]",
[
"[[data-variant=bordered][data-color=default]_+_&]:ml-[calc(theme(borderWidth.2)*-1)]",
"[[data-variant=ghost][data-color=default]_+_&]:ml-[calc(theme(borderWidth.2)*-1)]"
],

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add a file with all these selectors in ../utils to make it reusable.

Suggested change
"nextui-adjacent-default [&+.nextui-adjacent-default]:ml-[calc(theme(borderWidth.medium)*-1)]",
utils.collapseAdjacentVariantBorders.default,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When thinking about it using a class name also isn't that bad, it's pretty much just like using peer.

Copy link
Contributor

@jguddas jguddas Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this would also work.

Suggested change
"nextui-adjacent-default [&+.nextui-adjacent-default]:ml-[calc(theme(borderWidth.medium)*-1)]",
"[&+.border-medium.border-default]:ml-[calc(theme(borderWidth.medium)*-1)]",

The good part about this is we can add support for having different border widths other than medium.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jguddas

I have finally placed collapseAdjacentVariantBorders in the utils folder to make it reusable. This change also enables support for other border widths in the future.

@jguddas
Copy link
Contributor

jguddas commented Sep 19, 2023

Great work btw. This covers all the edge cases; I didn't think this would be achievable.

Copy link
Member

@jrgarciadev jrgarciadev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge thanks @chongruei @jguddas ❤️

@jguddas jguddas changed the title Fix/1626 fix: resolved border collapse issue #1626 when border variants are mixed in button group Oct 1, 2023
@jrgarciadev jrgarciadev merged commit 3aac9ba into nextui-org:main Oct 4, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - Button Group issues
4 participants